<?php

namespace app\modules\clinical\models;

use Yii;

/**
 * This is the model class for table "excel_et".
 *
 * @property integer $pk_id
 * @property integer $zishi_l
 * @property integer $zishi_r
 * @property integer $zhibi_l
 * @property integer $zhibi_r
 * @property integer $ajimi_l
 * @property integer $ajimi_r
 * @property integer $daoshui_l
 * @property integer $daoshui_r
 * @property integer $shaozi_l
 * @property integer $shaozi_r
 * @property integer $heshui_l
 * @property integer $heshui_r
 */
class ExcelEt extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'excel_et';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['zishi_l', 'zishi_r', 'zhibi_l', 'zhibi_r', 'ajimi_l', 'ajimi_r', 'daoshui_l', 'daoshui_r', 'shaozi_l', 'shaozi_r', 'heshui_l', 'heshui_r','yinjiu','pianzhongce','guanyongshou'], 'required'],
            [['zishi_l', 'zishi_r', 'zhibi_l', 'zhibi_r', 'ajimi_l', 'ajimi_r', 'daoshui_l', 'daoshui_r', 'shaozi_l', 'shaozi_r', 'heshui_l', 'heshui_r','yinjiu','yinjiuzhenchan','pianzhongce','guanyongshou'], 'integer'],
            
            [['zcleixing'], 'filter', 'filter' => function($array) {
                return is_array($array) ? implode("+", $array) : "";
            }],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'pk_id' => 'Pk ID',
            'zishi_l' => 'L: ',
            'zishi_r' => 'R: ',
            'zhibi_l' => 'L: ',
            'zhibi_r' => 'R: ',
            'ajimi_l' => 'L: ',
            'ajimi_r' => 'R: ',
            'daoshui_l' => 'L: ',
            'daoshui_r' => 'R: ',
            'shaozi_l' => 'L: ',
            'shaozi_r' => 'R: ',
            'heshui_l' => 'L: ',
            'heshui_r' => 'R: ',
            'yinjiu' => '是否饮酒：',
            'yinjiuzhenchan' => '若饮酒是否震颤：',
            'pianzhongce' => '偏重侧(左右)：',
            'guanyongshou' => '惯用手(左/右)：',
            'zcleixing' => '震颤类型：',
        ];
    }

    public static function getParams($type = false, $code = false)
    {
        $params = [
            'shifou' => ['1' => '是', '0' => '否'],
            'zuoyou' => ['1' => '左', '0' => '右'],
            'zcLeixing' => ['头部震颤(点头/摇头)', '下颌震颤', '静止性震颤','下肢震颤','其他'],
        ];

        if ($code !== false) {
            return ($type) ? $params[$type][$code] : '';
        }
        return ($type) ? $params[$type] : [];
    }

    static public function getZcClass($data) {
        $zcleixing = explode("+", $data);
        $string = "";

        foreach ($zcleixing as $key) {
            if ($key == '10') continue;
            if (preg_match('/^[0-9]+$/', $key)) {
                $string .= self::getParams('zcLeixing', intval($key)) . ", ";
            } else {
                $string .= str_replace("'", "", $key) . ", ";
            }
        }

        $string = substr($string, 0, strlen($string)-2);

        return $string;
    }
   

    public function defaultValue()
    {
        return ;
    }
}
